package controller

import (
	"database/sql"
	"fmt"
	"net/http"
)

func (p Routes) Sqlvisit(w http.ResponseWriter, r *http.Request) {
	db, err := sql.Open("mysql", "root:root@/kr_105?charset=utf8")

	//查询数据
	rows, err := db.Query("SELECT phone,nickname FROM u_user limit 5")
	checkErr(err)

	for rows.Next() {

		var phone string
		var nickname string

		err = rows.Scan(&phone, &nickname)
		checkErr(err)

		fmt.Fprint(w, phone, nickname)
	}
}

func checkErr(err error) {
	if err != nil {
		fmt.Println(err)

	}
}
